package com.xiaoxin.experience.service.sdk.rtsp;

import com.xiaoxin.experience.util.DateUtil;


/**
 * @author xiaoxin
 * Simple usage example:
 *   String liveRtspUrl = new DhRtspUrlBuilder("ip","password").build();
 *   String recordRtspUrl = new DhRtspUrlBuilder("ip","password").record("startTime","endTime").build();
 */
public class DhRtspUrlBuilder extends RtspUrlBuilder
{
    private static final String RECORD_DATE_FORMAT = "yyyy_MM_dd_HH_mm_ss";

    private String datePattern = DateUtil.YMDHMS_STD;

    public DhRtspUrlBuilder(String ip, String password)
    {
        super(ip,password);
    }

    public DhRtspUrlBuilder datePattern(String datePattern)
    {
        this.datePattern = datePattern;
        return this;
    }

    protected String buildLiveRtspUrl()
    {
        return commonPrefix() +
                "/cam/realmonitor?channel=" + channelNo + "&subtype=" + (streamType.value() - 1);
    }

    protected String buildRecordUrl()
    {
        return commonPrefix() +
                "/cam/playback?channel=" + channelNo + "&subtype=" + (streamType.value()-1) +
                "&starttime=" + adapt(startTime) + "&endtime=" + adapt(endTime);
    }

    public String adapt(String time)
    {
        return DateUtil.str2strDate(time, datePattern, RECORD_DATE_FORMAT);
    }
}
